package loginTest;

import initial.Init;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import org.openqa.selenium.By;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class Login extends Init {
    @ParameterizedTest
    @CsvSource("https://ceshi.cadexam.com:9102/resource-platform/#/login,15172344500,15172344500,https://ceshi.cadexam.com:9102/resource-platform/#/resource/title/titlemanage")
    @Order(1)
    public void login(String url,String username,String password,String newUrl) throws InterruptedException {
        webDriver.get(url);
        webDriver.manage().window().maximize();
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
        //输入账号密码
        System.out.println(username +":"+password);
        webDriver.findElement(By.xpath("/html/body/div/div/form/div[1]/div/div/div/input")).sendKeys(username);
        webDriver.findElement(By.xpath("/html/body/div/div/form/div[2]/div/div/div/input")).sendKeys(password);

        //todo：需要手动输入验证码
        sleep(10000);
        //点击登录
        webDriver.findElement(By.cssSelector("#app > div > form > div:nth-child(6) > div > button")).click();
        sleep(3000);
        //验证是否登录成功
        String cur = webDriver.getCurrentUrl();
        Assertions.assertEquals(newUrl,cur);
    }
}
